var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("BaseModuleUI"),
    a = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("CommonHelper"),
    c = e("EquipInfo"),
    d = e("Game"),
    h = e("RoleSoldierInfo"),
    _ = e("GuideMaskViewUI"),
    u = e("UIManager"),
    p = e("sdkConfig"),
    m = e("AD"),
    f = e("BuyEquipInfo"),
    g = e("node_team"),
    v = e("ReviveViewUI"),
    y = e("role_node"),
    S = e("small_map_node"),
    I = e("top_game_player"),
    w = cc._decorator,
    N = w.ccclass,
    C = w.property,
    b = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.left_base_node = null),
                (t.right_base_node = null),
                (t.role_soldier_view = null),
                (t.player_info_tip_view = null),
                (t.game_player_node = null),
                (t.game_over_anime = null),
                (t.small_map_node = null),
                (t.fight_top_node = null),
                (t.roleStartPosY = [60, 60, -150, -150, -320, -320]),
                (t.revive_view_node = null),
                (t.ai_num_equip_info = []),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.initView = function () {
                m.default.getInstance().hideBanner(),
                    p.default.platform != p.EPlatform.TikTok
                        ? m.default.getInstance().showBanner()
                        : (m.default.getInstance().StopRecorder(), m.default.getInstance().StartRecorder()),
                    this.emitEvent(a.default.SEND_COCOS_ANALYTICS, {name: "事件一", info: "进入战斗界面"}),
                    this.emitEvent(a.default.SEND_COCOS_ANALYTICS, {
                        name: "事件一",
                        info: "战斗模式：" + i.GlobalParams.ChangeGameMode
                    }),
                    (this.fight_top_node.active = !1),
                    s.default.getInstance().setMusicVolume(1),
                    (i.GlobalParams.gameMusicName = "fight_bgm"),
                    s.default.playGameBGM(),
                    (i.GlobalParams.PlayingRoleDie = []),
                    (i.GlobalParams.GameDestroyTower = [0, 0]),
                    (i.GlobalParams.MonsterDisNum = [
                        {num: 0, time: 0, exist: !1},
                        {num: 0, time: 0, exist: !1},
                        {num: 0, time: 0, exist: !1},
                        {num: 0, time: 0, exist: !1},
                        {num: 0, time: 1800, exist: !1}
                    ]),
                    (i.GlobalParams.BuyEquipInfo = []),
                    (i.GlobalParams.GamePlayerInfo = []),
                    (i.GlobalParams.PlayerJoinFight = !0),
                    this.setGamePlayerInfo(),
                    this.createRole(),
                    this.getAiMonEquipInfo(),
                    (this.game_over_anime.node.parent.active = !1);
                for (var e = 0; e < 3; e++)
                    this.game_player_node.children[e]
                        .getComponent(I.default)
                        .showPlayerInfo(i.GlobalParams.MatchMyIndex % 2 == 0 ? e + e : e + e + 1),
                        this.game_player_node.children[e + 3]
                            .getComponent(I.default)
                            .showPlayerInfo(i.GlobalParams.MatchMyIndex % 2 != 0 ? e + e : e + e + 1);
                i.GlobalParams.PlayGuideMode
                    ? this.scheduleOnce(function () {
                          cc.find("UIManager")
                              .getComponent(u.default)
                              .showPopup("GuideMaskViewUI", function (e) {
                                  e.getComponent(_.default).showGuideInfoView(3);
                              });
                      }, 0.5)
                    : this.gameStart();
            }),
            (t.prototype.gameStart = function () {
                var e = this;
                (i.GlobalParams.GameGiveUpTime = new Date().getTime() + 18e4),
                    s.default.getInstance().playFx("three_time"),
                    this.showTopTip(0),
                    this.scheduleOnce(function () {
                        (i.GlobalParams.GameStart = !0),
                            e.createSoldier(),
                            e.FightCountDown(),
                            s.default.getInstance().playFx("army_attack"),
                            e.showTopTip(1);
                    }, 4);
            }),
            (t.prototype.showTopTip = function (e) {
                var t = this;
                (this.fight_top_node.active = !0),
                    this.fight_top_node.setPosition(cc.v2(0, 250)),
                    (this.fight_top_node.children[0].active = 0 == e),
                    (this.fight_top_node.children[1].active = 1 == e),
                    cc
                        .tween(this.fight_top_node)
                        .to(2, {position: cc.v3(0, 300, 0)})
                        .call(function () {
                            t.fight_top_node.setPosition(cc.v2(0, 250)), (t.fight_top_node.active = !1);
                        })
                        .start();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(a.default.SEND_ROLE_BE_KILL_INFO, this.updatePlayerKillInfo, this),
                    this.attachEvent(a.default.SEND_GAME_OVER_INFO, this.showGameOver, this);
            }),
            (t.prototype.FightCountDown = function () {
                var e = this;
                if (i.GlobalParams.GameStart) {
                    i.GlobalParams.PlayingRoleDie.length > 0 && this.updatePlayingDie();
                    for (var t = 0; t < 5; t++) {
                        var o = i.GlobalParams.MonsterDisNum[t];
                        if (0 != o.time || o.exist) {
                            if (o.time > 0 && !o.exist) o.time--, this.small_map_node.showMonsterTime(t, o.time);
                            else if (-1 == o.time) continue;
                        } else (o.exist = !0), this.emitEvent(a.default.SEND_CREATE_MONSTER_INDEX, t + 1);
                    }
                    this.scheduleOnce(function () {
                        e.FightCountDown();
                    }, i.GlobalParams.GameUpdateTime);
                }
            }),
            (t.prototype.createSoldier = function () {
                var e = this;
                this.emitEvent(a.default.SEND_CREATE_SOLDIER_INFO),
                    this.scheduleOnce(function () {
                        e.createSoldier();
                    }, 30);
            }),
            (t.prototype.createRole = function () {
                for (var e = 0; e < i.GlobalParams.MatchGamePlayer.length; e++) this.creationRole(e);
            }),
            (t.prototype.updatePlayingDie = function () {
                for (var e = i.GlobalParams.PlayingRoleDie.length - 1; e > -1; e--) {
                    var t = i.GlobalParams.PlayingRoleDie[e],
                        o = t.role_index;
                    t.cound_down--;
                    var n = this.game_player_node.getChildByName("game_player_" + o);
                    (n.active = !0),
                        n.getComponent(I.default).updatePlayerInfo(t.cound_down),
                        this.revive_view_node &&
                            o == i.GlobalParams.MatchMyIndex &&
                            (this.revive_view_node.getComponent(v.default).showReviveTime(t.cound_down),
                            t.cound_down <= 0 &&
                                (p.default.platform == p.EPlatform.TikTok &&
                                    (m.default.getInstance().hideBanner(), m.default.getInstance().ResumeRecorder()),
                                this.revive_view_node.destroy())),
                        t.cound_down <= 0 &&
                            (o % 2 != i.GlobalParams.MatchMyIndex % 2 && (n.active = !1),
                            this.creationRole(o),
                            i.GlobalParams.PlayingRoleDie.splice(e, 1));
                }
            }),
            (t.prototype.creationRole = function (e) {
                var t = r.default.getInstance().getFightPrefab("role_" + i.GlobalParams.MatchGamePlayer[e].role_id),
                    o = cc.instantiate(t);
                (o.name = "role_team_" + e),
                    o.getComponent(y.default).showRoleInfo(e != i.GlobalParams.MatchMyIndex, e);
                var n = (e % 2 == 0 ? this.left_base_node : this.right_base_node).getPosition();
                (n.x += e % 2 == 0 ? -530 : 580),
                    (o.scaleX = e % 2 == 0 ? -1 : 1),
                    (n.y = this.roleStartPosY[e]),
                    o.setPosition(n),
                    o
                        .getComponent(g.default)
                        .setTeamInfo(-1 == o.scaleX ? d.TeamInfo.left_team : d.TeamInfo.right_team);
                var a = cc.instantiate(r.default.getInstance().getFightPrefab("player_info_node"));
                (a.zIndex = e == i.GlobalParams.MatchMyIndex ? 7 : e),
                    o.getComponent(y.default).setPlayerInfoNode(a),
                    a.setParent(this.player_info_tip_view),
                    o.setParent(this.role_soldier_view);
            }),
            (t.prototype.updatePlayerKillInfo = function (e, t) {
                var o = t;
                o.kill < 7 && o.be_kill < 7 && i.GlobalParams.MatchGamePlayer[o.kill].kill_info[0]++,
                    o.be_kill < 7 && i.GlobalParams.MatchGamePlayer[o.be_kill].kill_info[1]++,
                    o.help_kill &&
                        -1 != o.help_kill &&
                        o.be_kill < 7 &&
                        o.help_kill < 7 &&
                        (i.GlobalParams.MatchGamePlayer[o.help_kill].kill_info[2]++,
                        (i.GlobalParams.MatchGamePlayer[o.help_kill].exp_num += 117),
                        (i.GlobalParams.MatchGamePlayer[o.help_kill].coin += 100));
                for (var n = 0; n < i.GlobalParams.MatchGamePlayer.length; n++) {
                    var s = i.GlobalParams.MatchGamePlayer[n];
                    if (o.team != d.TeamInfo.rest_team) {
                        if ((o.team - 1) % 2 != n % 2)
                            if (o.be_kill < 7)
                                (s.exp_num += 300 * (o.kill == n ? 1 : 0.5)), (s.coin += 300 * (o.kill == n ? 1 : 0.5));
                            else
                                switch (o.be_kill) {
                                    case d.KillType.near_soldier:
                                        (s.exp_num += 20), (s.coin += 40);
                                        break;
                                    case d.KillType.far_soldier:
                                        (s.exp_num += 25), (s.coin += 65);
                                        break;
                                    case d.KillType.super_soldier:
                                        (s.exp_num += 100 * (o.kill == n ? 1 : 0.5)),
                                            (s.coin += 150 * (o.kill == n ? 1 : 0.5));
                                        break;
                                    case d.KillType.tower:
                                        (s.exp_num += 150), (s.coin += 200);
                                }
                    } else
                        switch (o.be_kill) {
                            case d.KillType.red_buff:
                            case d.KillType.blue_buff:
                                (s.exp_num += 100 * (o.kill == n ? 1 : 0.1)), (s.coin += 120 * (o.kill == n ? 1 : 0.1));
                                break;
                            case d.KillType.spider:
                                (s.exp_num += 150), (s.coin += 150);
                                break;
                            case d.KillType.dragon:
                                (s.exp_num += 200), (s.coin += 250);
                                break;
                            case d.KillType.big_dragon:
                                (s.exp_num += 300), (s.coin += 400);
                        }
                    if (s.exp_num >= d.default.level_exp[s.level - 1]) {
                        if (
                            ((s.exp_num -= d.default.level_exp[s.level - 1]),
                            s.level++,
                            n != i.GlobalParams.MatchMyIndex)
                        ) {
                            var c = l.default.getRandomInt(0, 1);
                            (c = s.skill_info[c] < 5 ? c : 0 == c ? 1 : 0), s.skill_info[c]++;
                            var _ = i.GlobalParams.MatchGamePlayer[n];
                            0 == c
                                ? (i.GlobalParams.GamePlayerInfo[n].skill_1 +=
                                      h.default.Role_info[_.role_id].S1_attack_up)
                                : 1 == c &&
                                  (i.GlobalParams.GamePlayerInfo[n].skill_2 +=
                                      h.default.Role_info[_.role_id].S2_attack_up);
                        }
                        this.playerLevelUp(n), this.emitEvent(a.default.SEND_PLAYER_LEVEL_UP_INFO, n);
                    }
                }
                this.aiBuyEquipInfo(),
                    this.emitEvent(a.default.SEND_UPDATE_MATCH_PLAYER_INFO),
                    o.be_kill == i.GlobalParams.MatchMyIndex &&
                        ((this.revive_view_node = cc.instantiate(
                            r.default.getInstance().getFightPrefab("ReviveViewUI")
                        )),
                        this.node.parent.addChild(this.revive_view_node));
            }),
            (t.prototype.showGameOver = function () {
                s.default.getInstance().playFx(i.GlobalParams.GamePlayerWin ? "victory" : "defeat"),
                    this.emitEvent(a.default.SEND_COCOS_ANALYTICS, {
                        name: "事件一",
                        info: i.GlobalParams.GamePlayerWin ? "游戏胜利" : "游戏失败"
                    }),
                    (this.game_over_anime.node.parent.active = !0),
                    this.game_over_anime.setAnimation(0, i.GlobalParams.GamePlayerWin ? "sl" : "sb", !1),
                    i.GlobalParams.gameShock.value && m.default.getInstance().vibrateShort(),
                    this.scheduleOnce(function () {
                        p.default.platform == p.EPlatform.TikTok && m.default.getInstance().StopRecorder(),
                            cc
                                .find("Canvas")
                                .addChild(cc.instantiate(r.default.getInstance().getFightPrefab("GameOverViewUI")));
                    }, 3);
            }),
            (t.prototype.getAiMonEquipInfo = function () {
                for (var e = 0; e < 6; e++) {
                    for (
                        var t = c.default.equip_nominate_info[i.GlobalParams.MatchGamePlayer[e].role_id], o = [], n = 0;
                        n < t.nom_equip.length;
                        n++
                    ) {
                        for (var a = c.default.eqquip_info[t.nom_equip[n]], r = 0; r < a.eq_need.length; r++)
                            o.push(a.eq_need[r]);
                        o.push(t.nom_equip[n]);
                    }
                    e != i.GlobalParams.MatchMyIndex
                        ? this.ai_num_equip_info.push(o)
                        : (this.ai_num_equip_info.push([]), (i.GlobalParams.MyNomEquipInfo = o));
                }
            }),
            (t.prototype.aiBuyEquipInfo = function () {
                for (
                    var e = this,
                        t = function (t) {
                            if (o.ai_num_equip_info[t].length > 0) {
                                for (
                                    var n = c.default.eqquip_info[o.ai_num_equip_info[t][0]].eq_sale,
                                        r = i.GlobalParams.MatchGamePlayer[t].equip_info,
                                        s = [],
                                        l = c.default.eqquip_info[o.ai_num_equip_info[t][0]],
                                        d = 0;
                                    d < l.eq_need.length;
                                    d++
                                )
                                    -1 != r.indexOf(l.eq_need[d]) &&
                                        ((n -= c.default.eqquip_info[l.eq_need[d]].eq_sale),
                                        s.push(r.indexOf(l.eq_need[d])));
                                if (i.GlobalParams.MatchGamePlayer[t].coin >= n) {
                                    for (d = 0; d < s.length; d++) r[s[d]] = 0;
                                    (r[r.indexOf(0)] = o.ai_num_equip_info[t][0]),
                                        (i.GlobalParams.MatchGamePlayer[t].coin -= n),
                                        (i.GlobalParams.MatchGamePlayer[t].equip_info = r),
                                        o.ai_num_equip_info[t].splice(0, 1),
                                        f.default.playerBuyEquipInfo(t, function () {
                                            e.emitEvent(a.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO, t);
                                        });
                                }
                            }
                        },
                        o = this,
                        n = 0;
                    n < this.ai_num_equip_info.length;
                    n++
                )
                    t(n);
            }),
            (t.prototype.setGamePlayerInfo = function () {
                f.default.buyEquipInit();
                for (var e = 0; e < 6; e++) {
                    var t = i.GlobalParams.MatchGamePlayer[e],
                        o = h.default.Role_info[t.role_id],
                        n = f.default.getPlayerInit(),
                        a = i.GlobalParams.PlayGuideMode && e % 2 != i.GlobalParams.MatchMyIndex % 2;
                    (n.attack = o.C_attack * (a ? 0.8 : 1)),
                        (n.skill_1 = o.S1_attack * (a ? 0.8 : 1)),
                        (n.skill_2 = o.S2_attack * (a ? 0.8 : 1)),
                        (n.hp = o.C_hp * (a ? 0.8 : 1)),
                        (n.move_speed = 25),
                        (n.attack_speed = 1),
                        (n.cool_1 = h.default.Hore_Skill_Info[t.role_id].one_time),
                        (n.cool_2 = h.default.Hore_Skill_Info[t.role_id].two_time),
                        0 == t.dower_info[0]
                            ? (n.attack += t.dower_info[1])
                            : 1 == t.dower_info[0]
                            ? (n.move_speed += t.dower_info[1])
                            : 2 == t.dower_info[0]
                            ? (n.hp += t.dower_info[1])
                            : 3 == t.dower_info[0]
                            ? (n.attack_speed -= t.dower_info[1])
                            : 4 == t.dower_info[0] && ((n.cool_1 -= t.dower_info[1]), (n.cool_2 -= t.dower_info[1])),
                        i.GlobalParams.GamePlayerInfo.push(n);
                }
            }),
            (t.prototype.playerLevelUp = function (e) {
                var t = i.GlobalParams.MatchGamePlayer[e],
                    o = h.default.Role_info[t.role_id];
                (i.GlobalParams.GamePlayerInfo[e].attack += o.C_attack_up),
                    (i.GlobalParams.GamePlayerInfo[e].hp += o.C_hp_up);
            }),
            __decorate([C(cc.Node)], t.prototype, "left_base_node", void 0),
            __decorate([C(cc.Node)], t.prototype, "right_base_node", void 0),
            __decorate([C(cc.Node)], t.prototype, "role_soldier_view", void 0),
            __decorate([C(cc.Node)], t.prototype, "player_info_tip_view", void 0),
            __decorate([C(cc.Node)], t.prototype, "game_player_node", void 0),
            __decorate([C(sp.Skeleton)], t.prototype, "game_over_anime", void 0),
            __decorate([C(S.default)], t.prototype, "small_map_node", void 0),
            __decorate([C(cc.Node)], t.prototype, "fight_top_node", void 0),
            __decorate([N], t)
        );
    })(n.default);
o.default = b;
